package com.gdth.log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class StreamConsumer extends Thread {
    InputStream is;
    List<String> list;

    StreamConsumer(InputStream is) {
        this.is = is;
    }

    StreamConsumer(InputStream is, List<String> list) {
        this.is = is;
        this.list = list;
    }

    public void run() {
        try {
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                if (list != null) {
                    list.add(line);
                }
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

}
